package org.jeecg.modules.report.hotel.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.modules.report.hotel.entity.BedReport;
import org.jeecg.modules.report.hotel.entity.HotelRoom;
import org.jeecg.modules.report.hotel.entity.LwgyHotelReport;
import org.jeecg.modules.report.hotel.entity.RoomReport;
import org.jeecg.modules.report.hotel.service.HotelReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.*;

/**
 * TODO
 *
 * @author CSD
 * @date 2021-04-08 13:31
 */
@Api(tags="住宿统计")
@RestController
@RequestMapping("/report/lwgyHotelReport")
@Slf4j
public class HotelReportController  extends JeecgController<LwgyHotelReport, HotelReportService> {

    @Autowired
    private HotelReportService hotelReportService;


    @GetMapping("/getNoneRoomByCampus")
    public Result<?>getNoneRoomByCampus(String campus){
        Map<String, Integer> map = hotelReportService.getNoneRoomByCampus(campus);
        return Result.OK(map);
    }
    @GetMapping("/getUnderRoomByCampus")
    public Result<?>getUnderRoomByCampus(String campus){
        Map<String, Integer> map = hotelReportService.getUnderRoomByCampus(campus);
        return Result.OK(map);
    }

    @GetMapping("/list")
    public Result<?>list(String campus){
//        List<HotelRoom> list = hotelReportService.getList(campus);
        Page<HotelRoom> page = new Page<>(1, 100);
        IPage<HotelRoom> pageList = hotelReportService.queryPageListCustom(page, campus);
        return Result.OK(pageList);
    }

    @PostMapping("/roomUseReport")
    public Result<?>roomUseReport(@RequestBody RoomReport roomReport){
        List<RoomReport> reportList = hotelReportService.roomUseReport(roomReport);
        List<Map<String,Integer>>roomUseList = new ArrayList<>(5);
        Map<String,Integer>map1 = new LinkedHashMap<>(6);
        Map<String,Integer>map2 = new LinkedHashMap<>(6);
        Map<String,Integer>map3 = new LinkedHashMap<>(6);
        for (RoomReport report : reportList) {
            map1.put(report.getName(),report.getNullRoomNum());//空房间
            map2.put(report.getName(),report.getUnderRoomNum());//未满房间
            map3.put(report.getName(),report.getFullRoomNum());//已满房间
        }
        roomUseList.add(map1);
        roomUseList.add(map2);
        roomUseList.add(map3);
        return Result.OK(roomUseList);
    }
    @PostMapping("/bedsUseReport")
    public Result<?>bedsUseReport(@RequestBody BedReport bedReport){
        List<BedReport> reportList = hotelReportService.bedUseReport(bedReport);
        List<Map<String,Integer>> bedsUseList = new ArrayList<>(5);
        Map<String,Integer>map1 = new LinkedHashMap<>(6);
        Map<String,Integer>map2 = new LinkedHashMap<>(6);
        Map<String,Integer>map3 = new LinkedHashMap<>(6);
        for (BedReport report : reportList) {
            map1.put(report.getName(),report.getTotalBedNum());//总床位
            map2.put(report.getName(),report.getNullBedNum());//空床位
            map3.put(report.getName(),report.getOccupancyBedNum());//已住床位
        }
        bedsUseList.add(map1);
        bedsUseList.add(map2);
        bedsUseList.add(map3);
        return Result.OK(bedsUseList);
    }

    @PostMapping("/roomUseReportList")
    public Result<?> roomUseReportList(@RequestBody RoomReport roomReport){
        List<RoomReport> reportList = hotelReportService.roomUseReport(roomReport);
        IPage<RoomReport>reportIPage = new Page<>(0,100);
        reportIPage.setRecords(reportList);
        return Result.OK(reportIPage);
    }
    @PostMapping("/bedUseReportList")
    public Result<?> bedUseReportList(@RequestBody BedReport bedReport){
        List<BedReport> reportList = hotelReportService.bedUseReport(bedReport);
        IPage<BedReport>reportIPage = new Page<>(0,100);
        reportIPage.setRecords(reportList);
        return Result.OK(reportIPage);
    }

}
